-
Notifications
You must be signed in to change notification settings - Fork 9
update MMU code #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
update MMU code #39
Conversation
44f73e9
to
4a10229
Compare
I used and tested this as part of a zynq7000 ethernet implementation now. |
4a10229
to
53091c4
Compare
#[derive(Debug, Copy, Clone)] | ||
#[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
pub struct SectionAttributes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bitbybit::bitfield
struct may be easier to use here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, that need is covered by the L1Section
. This is more of a high-level attribute collection which also abstracts the various bits into their high-level meaning. Maybe a section_attribute
method for the L1 section would be better? It does a lot of stuff usually covered by bitbybit though, admittedly..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just seems unnecessary to have to do all the shifting manually.
Perhaps you could have a public type which is normal, and a private type that is a bitbybit bitfield, and an Into impl to convert between them. Then you can let bitfield macro do the hard work, but it's not in the public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding this API for the L1 section:
#[inline]
pub fn section_attrs(&self) -> Result<SectionAttributes, InvalidL1EntryType> {
SectionAttributes::from_raw(self.raw_value())
}
#[inline]
pub fn set_section_attrs(&mut self, section_attrs: SectionAttributes) {
self.raw_value = self.base_addr().as_u32() | section_attrs.raw();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I'll have a look at bitbybit to avoid the boilerplate bit shifting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, maybe? I don't have a good handle on how this API is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll figure out something that makes sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I updated the API. Less bitshifting, and it is actually a lot better from a user perspective as well.
e464ad7
to
03501fe
Compare
pub struct L1Section { | ||
/// Section base address. | ||
#[bits(20..=31, rw)] | ||
base_addr: u12, | ||
/// Non-global bit. | ||
#[bit(16, rw)] | ||
#[bit(17, rw)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worrying that I just found this because I wanted to add a builder..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit PR for this bugfix: #45
#[derive(Debug, Copy, Clone)] | ||
#[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
pub struct SectionAttributes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I updated the API. Less bitshifting, and it is actually a lot better from a user perspective as well.
#[inline] | ||
pub fn set_section_attrs(&mut self, section_attrs: SectionAttributes) { | ||
self.raw_value = | ||
((self.base_addr().value() as u32) << 20) | section_attrs.l1_section_part().raw_value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: I could also write this using the builder API. It would be very verbose, but shouldn't matter for performance.
| ((section_attrs.memory_attrs.b as u32) << 2) | ||
| L1EntryType::Section as u32; | ||
Self::new_with_raw_value(raw) | ||
Self::new_with_raw_value((higher_bits << 20) | section_attrs.l1_section_part().raw_value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also write this using the builder API. It would be very verbose, but shouldn't matter for performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Set the section attributes without changing the address.
#[inline]
pub fn set_section_attrs(&mut self, section_attrs: SectionAttributes) {
let attrs = section_attrs.l1_section_part();
*self = L1Section::builder()
.with_base_addr(self.base_addr())
.with_ng(attrs.ng())
.with_s(attrs.s())
.with_apx(attrs.apx())
.with_tex(attrs.tex())
.with_ap(attrs.ap())
.with_p_bit(attrs.p_bit())
.with_domain(attrs.domain())
.with_xn(attrs.xn())
.with_c(attrs.c())
.with_b(attrs.b())
.with_entry_type(attrs.entry_type())
.build()
}
to be honest, I prefer the first one..
Still needs to be tested